#include "recboxitem.h"
#include "ui_recboxitem.h"
#include<QDebug>
#include<QPropertyAnimation>
RecBoxItem::RecBoxItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RecBoxItem)
{
    ui->setupUi(this);
    ui->recMusicImage->installEventFilter(this);
}

RecBoxItem::~RecBoxItem()
{
    delete ui;
}

void RecBoxItem::setBoxItemText(const QString &text)//为recboxitemtext设置文本
{
   ui->recBoxItemText->setText(text);
}

void RecBoxItem::setrecMusicImage(const QString &imagePath)//为recmusicimage设置图片
{
    QString path="border-image:url("+imagePath+");";
    ui->recMusicImage->setStyleSheet(path);
    ui->recMusicImage->setScaledContents(true);
}

bool RecBoxItem::eventFilter(QObject *watched, QEvent *event)
{
   if(watched==ui->recMusicImage)
   {
       if(QEvent::Enter==event->type())
       {
           QPropertyAnimation*animal=new QPropertyAnimation(ui->recMusicImage,"geometry");
           animal->setDuration(300);
           animal->setLoopCount(1);
           animal->setStartValue(QRect(9,11,ui->recMusicImage->width(),ui->recMusicImage->height()));
           animal->setEndValue(QRect(9,0,ui->recMusicImage->width(),ui->recMusicImage->height()));
           animal->start();
           connect(animal,&QPropertyAnimation::finished,this,[=](){
               delete animal;
           });
       }
       else if(QEvent::Leave==event->type())
       {
           QPropertyAnimation*animal=new QPropertyAnimation(ui->recMusicImage,"geometry");
           animal->setDuration(300);
           animal->setLoopCount(1);
           animal->setStartValue(QRect(9,0,ui->recMusicImage->width(),ui->recMusicImage->height()));
           animal->setEndValue(QRect(9,11,ui->recMusicImage->width(),ui->recMusicImage->height()));
           animal->start();
           connect(animal,&QPropertyAnimation::finished,this,[=](){
               delete animal;
           });
       }
       return true;
   }

   return QObject::eventFilter(watched,event);
}


